package com.okta.sdk;

import com.google.common.base.Splitter;
import com.okta.sdk.framework.ApiClientConfiguration;

import java.io.IOException;
import java.util.Iterator;
import java.util.Scanner;

/**
 * Created by zq_ja on 2017/8/10 0010.
 */
public class Test {
    public static void main(String[] args) {
        String baseurl = "https://dev-392443.oktapreview.com";
        String token = "005eICa1_rznbl3IvWQynBMwDMbARtueBGR0quBYmv";
        ApiClientConfiguration apiClientConfiguration = new ApiClientConfiguration(baseurl, token);
        OktaSdk oktaSdk = new OktaSdk(apiClientConfiguration);

        String emails = String.valueOf(read());

        Iterable<String> emailStrings = Splitter.on(",").omitEmptyStrings().trimResults().split(emails);
        Iterator<String> iterator = emailStrings.iterator();
        while (true) {
            if (iterator.hasNext()) {
                String email = iterator.next();
                try {
                    oktaSdk.getUserApiClient().deleteUser(email);
                    oktaSdk.getUserApiClient().deleteUser(email);
                    System.out.println("delete <" + email + "> success.");
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                    continue;
                }
            } else {
                break;
            }
        }
    }

    public static String read() {
        System.out.print("please input emails joined by ',':");
        return String.valueOf(new Scanner(System.in).nextLine()).toString();
    }
}
